MAC Linux @ office

Linux bridge

How to make your home backbone

Languages:

English

Contents:

Intro

I've bought 2 NIC as Network Adapters, like Gigabit ethernet. This how-to help us to undestand how 2 box linux can help to be a backbone homebrew. We are NOT going to explain why we had choose linux or kernel or bridge utils configuration aka brctl.
Maybe we(you) spent 10 minutes about nothing, anyway listen us:

Troubles

We have noticed about unstable bridge forwarding activity when cables are unplugged and plugged some times. This make linux box unworkable like bridge. Anyway IP forwarding is going very well.

Solution

Discovered: Linux reset bridge's ports status whenever ethernet interfaces toggle UP or DOWN We like to use this feature to make bridging more stable and reliable.
How we can do this? Interface Plug Daemon aka ifplugd solved our issues!

Gentoo configuration

Either Linux boxes are bundled with Linux Gentoo Distro.
/etc/conf.d/ifplugd
Enable all bridged interfaces

INTERFACES="eth0 eth1"

cat /etc/conf.d/net
You need this to avoid DHCP by init.d scripts
iface_eth0="0.0.0.0"
iface_eth1="0.0.0.0"
We post our bridge startup script, you can write own or check lates init.d scripts for bridging interfaces:
cat /etc/init.d/bridge
#!/sbin/runscript

opts="start stop force"

depend() {
        use net.eth0
        after net.eth0
}

start() {
        ebegin "Starting Bridge"
        /sbin/brctl addbr br0
        /sbin/brctl addif br0 eth0
        /sbin/brctl addif br0 eth1
        /sbin/ifconfig eth0 down
        /sbin/ifconfig eth1 down
        /sbin/ifconfig eth0 0.0.0.0 up
        /sbin/ifconfig eth1 0.0.0.0 up
        /sbin/ifconfig br0 192.168.0.1 up
        # we have a router for IP protocol, have you?
        echo "1" > /proc/sys/net/ipv4/ip_forward
        /sbin/route add default gw 192.168.0.254
        eend $?
}

force() {
        ebegin "Stopping Bridge"
        # when we force shutdown we can put an ip on interfaces to allow host be reached
        /sbin/ifconfig br0 down
        /sbin/brctl delbr br0
        /sbin/ifconfig eth0 down
        /sbin/ifconfig eth1 down
        /sbin/ifconfig eth0 192.168.0.1 up
        /sbin/route add default gw 192.168.0.254
        eend $?
}
stop() {
        ebegin "Stopping Bridge"
        eend $?
        # we like to NOT disable bridging
}

Tips: You need to link net.eth0 and net.eth1 to net.lo to enable UP and DOWN toggle on ifplugd actions.